#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;
//constexpr int mod = 998244353;
constexpr int mod = 1e9 + 7;

int reduce(int x) {
	if(x < 0) x += mod;
	if(x >= mod) x -= mod;
	return x;
}

template < typename T > T qp(T x, ll t) { T res = 1; for(; t; t >>= 1, x *= x) if(t & 1) res *= x; return res; }

struct Z { // modint
	int x;
	Z(int x = 0) : x(reduce(x)) {}
	Z(ll x) : x(reduce(x % mod)) {}
	Z operator -() const { return Z(reduce(mod - x)); }
	int val() const { return x; }
	Z inv() const { assert(x); return qp(*this, mod - 2); }
	Z &operator += (const Z &t) { x = reduce(x + t.x); return *this; }
	Z &operator -= (const Z &t) { x = reduce(x - t.x); return *this; }
	Z &operator *= (const Z &t) { x = (ll)x * t.x % mod; return *this; }
	Z &operator /= (const Z &t) { return *this *= t.inv(); }
	friend Z operator + (const Z &a, const Z &b) { Z res = a; res += b; return res; }
	friend Z operator - (const Z &a, const Z &b) { Z res = a; res -= b; return res; }
	friend Z operator * (const Z &a, const Z &b) { Z res = a; res *= b; return res; }
	friend Z operator / (const Z &a, const Z &b) { Z res = a; res /= b; return res; }
	friend ostream & operator << (ostream &out, const Z &x) {
		out << x.val();
		return out;
	}
};

Z fac[N], ifac[N];
Z C(int x, int y) { return x < 0 || y < 0 || x < y ? Z(0) : fac[x] * ifac[y] * ifac[x - y]; }
void init(int l) {
	fac[0] = 1; rep(i, 1, l) fac[i] = fac[i - 1] * Z(i); ifac[l] = fac[l].inv();
	per(i, l - 1, 0) ifac[i] = ifac[i + 1] * Z(i + 1);
}

char n[55];
int len;

Z f[12][55][12][55];

Z calc(vec pot, int clen) {
	rep(i, 0, 9) rep(j, 0, clen)
		rep(k, 0, 9) rep(t, 0, len) f[i][j][k][t] = 0;
	
	rep(i, 0, clen) f[0][i][0][i + pot[0]] = ifac[i];//C(clen, i);
	
	rep(i, 1, 9) rep(j, 0, clen) rep(k, 0, 9) rep(t, 0, len) if(f[i - 1][j][k][t].val()) {
		rep(v, 0, clen - j)
			f[i][j + v][v + pot[i] >= t ? i : k][v + pot[i] >= t ? v + pot[i] : t] +=
			f[i - 1][j][k][t] * ifac[v]; //C(clen - j, v);
	}
	Z ret = 0;
	rep(k, 0, 9) rep(t, 0, len) ret += f[9][clen][k][t] * k * fac[clen];
	return ret;
}

void solve() {
	scanf("%s", n + 1); len = strlen(n + 1);
	vec pot(10, 0);
	Z ret = 0;
	rep(i, 1, len) {
		rep(j, i == 1 ? 1 : 0, n[i] - '0' - 1) {
			pot[j]++;
			ret += calc(pot, len - i);
			pot[j]--;
		}
		pot[n[i] - '0']++;
	}
	ret += calc(pot, 0);
	pot = vec(10, 0);
	rep(i, 2, len) { // 1 ~ i - 1 : 0
		rep(j, 1, 9) {
			pot[j]++;
			ret += calc(pot, len - i);
			pot[j]--;
		}
	}
	printf("%d\n", ret.val());
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	init(555);
	for(int T = in; T; T--) solve();
	return 0;
}
